package com.ztz.mynewdemo.fragment;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.flyco.tablayout.SlidingTabLayout;
import com.ztz.mynewdemo.R;
import com.ztz.mynewdemo.adapter.MyAdapter;

import java.util.ArrayList;
import java.util.List;

/**
 * Created by wqewqe on 2017/5/16.
 */

public class NewsFragment extends Fragment {
    ViewPager newsViewpager;
    SlidingTabLayout tabLayout;
    MyAdapter adapter;
    List<Fragment> fragmentList=new ArrayList<>();
    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view=inflater.inflate(R.layout.news_fragment,container,false);
        return view;
    }

    @Override
    public void onViewCreated(View view, @Nullable Bundle savedInstanceState) {
        super.onViewCreated(view, savedInstanceState);
        newsViewpager=(ViewPager)view.findViewById(R.id.news_viewPager);
        tabLayout=(SlidingTabLayout) view.findViewById(R.id.tab_slid);
        fragmentList.add(new TopLineFragment());
        fragmentList.add(new SocietyFragment());
        fragmentList.add(new DomesticFragment());
        fragmentList.add(new ScienceFragment());
        if(fragmentList!=null) {
            adapter = new MyAdapter(getFragmentManager(), fragmentList);
        }
        newsViewpager.setOffscreenPageLimit(4);
        newsViewpager.setAdapter(adapter);
        tabLayout.setViewPager(newsViewpager);
    }
}
